package org.ihelpuoo.weboo.tag.core;

import javax.servlet.jsp.JspException;

import org.ihelpuoo.lang.StringUtils;
import org.ihelpuoo.weboo.tag.Processor;
import org.ihelpuoo.weboo.tag.WebooTag;

public class ProcessorTag extends WebooTag
{
	private static final long	serialVersionUID	= 3046785657992176179L;

	private String				name;
	private String				module;
	private String				value;

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getModule()
	{
		return module;
	}

	public void setModule(String module)
	{
		this.module = module;
	}

	public String getValue()
	{
		return value;
	}

	public void setValue(String from)
	{
		this.value = from;
	}

	@Override
	public void end() throws JspException
	{
		if (StringUtils.isEmpty(value))
			throw new JspException("Lack processor declaration!");
		try
		{
			Processor pro = (Processor)this.nut().getObject(value);
			Object value = pro.execute(getProcessContext(module));
			pageContext.setAttribute(name,value);
		}
		catch (Exception e)
		{
			throw new JspException(e);
		}
	}

	@Override
	protected void start() throws JspException
	{
	}

}
